import 'dart:math';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rider/main/widgets/ui_constant.dart';

class ScreenFit {
  static late MediaQueryData _mq;
  static double rs = 1;
  static const Widget empty = SizedBox.shrink();

  static void initialize(BuildContext context, {double standardWidth = 375}) {
    _mq = MediaQuery.of(context);
    var width = min(_mq.size.width, _mq.size.height);
    rs = width / standardWidth;
  }
}

extension DoubleFit on double {
  double get rpx {
    return this * ScreenFit.rs;
  }

  SizedBox get hspace {
    return SizedBox(
      height: this * ScreenFit.rs,
    );
  }

  SizedBox get wspace {
    return SizedBox(
      width: this * ScreenFit.rs,
    );
  }

  Container get hLine16 {
    return Container(
        margin: EdgeInsets.only(left: 16.rpx),
        height: this * ScreenFit.rs,
        color: UIColor.color_divider);
  }

  Container get hLine {
    return Container(height: this * ScreenFit.rs, color: UIColor.color_divider);
  }

  Container get wLine {
    return Container(width: this * ScreenFit.rs, color: UIColor.color_divider);
  }
}

extension IntFit on int {
  double get rpx {
    return this * ScreenFit.rs;
  }

  SizedBox get hspace {
    return SizedBox(
      height: this * ScreenFit.rs,
    );
  }

  SizedBox get wspace {
    return SizedBox(
      width: this * ScreenFit.rs,
    );
  }

  Container get hLine {
    return Container(height: this * ScreenFit.rs, color: UIColor.color_divider);
  }

  Container get wLine {
    return Container(width: this * ScreenFit.rs, color: UIColor.color_divider);
  }
}
